package model;

// Generated 18 oct. 2012 23:06:13 by Hibernate Tools 4.0.0

import java.util.List;
import javax.naming.InitialContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Example;

/**
 * Home object for domain model class Word.
 * @see model.Word
 * @author Hibernate Tools
 */
public class WordHome  extends HomeObject {

	private static final Log log = LogFactory.getLog(WordHome.class);

	private final SessionFactory sessionFactory = getSessionFactory();

	public void persist(Word transientInstance) {
		log.debug("persisting Word instance");
		try {
			sessionFactory.getCurrentSession().persist(transientInstance);
			log.debug("persist successful");
		} catch (RuntimeException re) {
			log.error("persist failed", re);
			throw re;
		}
	}

	public void attachDirty(Word instance) {
		log.debug("attaching dirty Word instance");
		try {
			sessionFactory.getCurrentSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Word instance) {
		log.debug("attaching clean Word instance");
		try {
			sessionFactory.getCurrentSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void delete(Word persistentInstance) {
		log.debug("deleting Word instance");
		try {
			sessionFactory.getCurrentSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Word merge(Word detachedInstance) {
		log.debug("merging Word instance");
		try {
			Word result = (Word) sessionFactory.getCurrentSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public Word findById(java.lang.Integer id) {
		log.debug("getting Word instance with id: " + id);
		try {
			Word instance = (Word) sessionFactory.getCurrentSession().get(
					"model.Word", id);
			if (instance == null) {
				log.debug("get successful, no instance found");
			} else {
				log.debug("get successful, instance found");
			}
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Word instance) {
		log.debug("finding Word instance by example");
		try {
			List results = sessionFactory.getCurrentSession()
					.createCriteria("model.Word").add(Example.create(instance))
					.list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}
}
